package com.burgeon.backend.SHOP.controller;

import com.burgeon.backend.SHOP.entity.CouponType;
import com.burgeon.backend.SHOP.entity.Goods;
import com.burgeon.backend.SHOP.service.BirthdayCouponService;
import com.burgeon.backend.stsutil.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.text.ParseException;
import java.util.List;


@RestController
@RequestMapping("shop/birthdayCoupon")
public class BirthdayCouponController extends BaseController {

    @Autowired
    private BirthdayCouponService birthdayCouponService;


    /**
     * @author: 伯俊软件
     * @description: 生日优惠券
     * @date: 2021/7/28 17:47
     * @param session
     * @return com.burgeon.backend.stsutil.ResponseResult<com.burgeon.backend.SHOP.entity.CouponType>
     */
    @RequestMapping("findCoupon")
    public ResponseResult<CouponType> findBirthdayCoupon(HttpSession session) throws ParseException {

        if (null == session.getAttribute("uid")){
            return new ResponseResult<>(NOTLOG);
        }
        String uid = session.getAttribute("uid").toString();
        String token = session.getAttribute("token").toString();
        CouponType data = birthdayCouponService.findBirthdayCoupon(token,uid);
        return new ResponseResult<CouponType>(SUCCESS,data);
    }


    /**
     * @author: 伯俊软件
     * @description: 推荐商品
     * @date: 2021/7/28 17:47
     * @param session
     * @param logo：A：综合 B：销量 C:积分
     * @param flag：m：正 n:负
     * @return com.burgeon.backend.stsutil.ResponseResult<java.util.List<com.burgeon.backend.SHOP.entity.Goods>>
     */
    @RequestMapping("recommended")
    public ResponseResult<List<Goods>> recommendedGoods(HttpSession session, String logo, String flag){
        String token = session.getAttribute("token").toString();
        List<Goods> data =  birthdayCouponService.recommendedGoods(token,logo,flag);
        return new ResponseResult<>(SUCCESS,data);
    }

    /**
     * @author: 伯俊软件
     * @description: 商品搜索
     * @date: 2021/7/29 15:06
     * @param message：搜索内容
     * @param session
     * @return com.burgeon.backend.stsutil.ResponseResult<java.util.List<com.burgeon.backend.SHOP.entity.Goods>>
     */
    @RequestMapping("findGoodsData")
    public ResponseResult<List<Goods>> findGoodsData(String  message, HttpSession session){
        String token = session.getAttribute("token").toString();
        List<Goods> data = birthdayCouponService.findGoodsData(message,token);
        return new ResponseResult<>(SUCCESS,data);
    }


    /**
     * @author: 伯俊软件
     * @description: 领取生日优惠券
     * @date: 2021/7/29 14:55
     * @param cid：优惠券ID
     * @param session
     * @return com.burgeon.backend.stsutil.ResponseResult<java.lang.Void>
     */
    @RequestMapping("getBirthdayCoupon")
    public ResponseResult<Void> getBirthdayCoupon(String cid , HttpSession session) throws Exception {
        String uid = null;
        if (null != session.getAttribute("uid")) {
            uid = session.getAttribute("uid").toString();
        }else {
            return new ResponseResult<>(NOTLOG);
        }
        String phone = session.getAttribute("phone").toString();
        String token = session.getAttribute("token").toString();
        String openid = session.getAttribute("app_openid").toString();
        birthdayCouponService.getBirthdayCoupon(cid,uid,token,phone,openid);
        return new ResponseResult<>(SUCCESS);
    }

}
